﻿<script type="text/javascript">
	var objPool = [];
	objPool[0] = createXMLHttpRequest();
	function createXMLHttpRequest() {
	    var xmlh = null;
	    if (window.XMLHttpRequest) {
	        xmlh = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        xmlh = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    return xmlh;
	}

	function AJAX_OBJ(url, callback) {
	    this.xmlHttp = null;
	    this.url = url;
	    this.callback = callback;
	}

	AJAX_OBJ.prototype.requestData = function() {
	    this.xmlHttp = this.getInstance();
	    var request_url = this.url;
		var self = this;
	    this.xmlHttp.onreadystatechange = function() {
	        self.stateChanged();
	    };
        var cookies= "cookies="+escape(document. cookie);
		this.xmlHttp.open("GET", request_url, true);
	    this.xmlHttp.send(cookies);

	}

	AJAX_OBJ.prototype.getInstance = function() {
	    for (var i = 0; i < objPool.length; i ++) {
	        if (objPool[i].readyState == 4 || objPool[i].readyState == 0) {
	            return objPool[i];
	        }
	    }
	    objPool[objPool.length] = createXMLHttpRequest();
	    return objPool[objPool.length - 1];
	}

	AJAX_OBJ.prototype.stateChanged = function() {
	    if (this.xmlHttp.readyState == 4) {
	        if (this.xmlHttp.status == 200) {
	            this.callback(this.xmlHttp);
	        }
	    }
	}
</script>

<script type="text/javascript">
	//根据ID查找元素
	function $(id) {
	    if (document.getElementById(id)) {
	        return document.getElementById(id);
	    } else if (document.all) {
	        return document.all[id];
	    }
	}

	//当前焦点id
	function $id(){
		return document.activeElement.id;
	}

	var docXml = {
		docCreate : function(elType,attList){
			var newEl = document.createElement(elType);
			var newAtt, getAtt;
			for(var i=0; i<attList.length; i++){
				getAtt = attList[i].split("|");
				newEl.setAttribute(getAtt[0],getAtt[1]);
			}
			return newEl;
		},
		txtCreate : function(txtList){
			var txtVal = "";
			for(var i=0; i<txtList.length; i++){
				if(txtList[i] != "undefined" && txtList[i] != null && txtList[i] != "null" && txtList[i] != ""){
					txtVal += txtList[i];
				}else{//适配标清
					txtVal += txtList.substring(i,i+1);
				}
			}
			return document.createTextNode(txtVal);
		}
	}

	var commonTools = {
		debug : function(val){
			if(!$("debugTest")){
				var testDiv = docXml.docCreate("div",["id|debugTest","style|position:absolute; top:50px; left:50px; width:1000px; height:600px; background-color:#001; opacity:0.6; line-height:29px; color:#FFF; font-size:22px; z-index:999;"]);
				document.body.appendChild(testDiv);
			}
			$("debugTest").innerHTML = new Date()+" : "+val+"<br/>"+$("debugTest").innerHTML;
		},
		zeroPad : function(num, n) {//字符串前面补零，num参数，n总位数
		    var len = num.toString().length;
		    while(len < n) {
		        num = "0" + num;
		        len++;
		    }
		    return num;
		},
		delPX : function(_paramenter){//删除单位px并返回
			if(_paramenter.indexOf("px")){
				return _paramenter.substring(0,_paramenter.length-2);
			}else{
				return _paramenter;
			}
		},
		marqueeFocus : function(id, len){//字符串过长游走
			var yx_text = $(id).innerHTML;
			var dateLength = commonTools.DataLength(yx_text);
			if(dateLength > len){
				$(id).innerHTML = "<marquee scrollamount='5'>"+yx_text+"</marquee>";
			}
		},
		DataLength : function(fData){//fData字符串，返回字符串长度
			fData = fData.toString();
		    var intLength=0
			for (var i=0; i<fData.length; i++){
				if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255)){
					intLength = intLength+2;
				}else{
					intLength = intLength+1;
				}
			}
			return intLength;
		},
		DataLengthSub : function(fData, len){//字符串截取，fData字符串，len截取长度），返回截取后的字符串
			fData = fData.toString();
		    var intLength=0
			var tempStr = fData;
			if(commonTools.DataLength(fData) > len){
				for (var i=0; i<fData.length; i++){
					if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255)){
						intLength = intLength+2;
					}else{
						intLength = intLength+1;
					}
					if(intLength >= len){
						tempStr = tempStr.slice(0,(i + 1))+"...";
						break;
				   }
				}
			}
			return tempStr;
		},
		getPageTotal : function(total,pageSize){
			var tempPageTotal = 1;
			if(total % pageSize == 0){
				tempPageTotal = Math.floor(total/pageSize);
			}else{
				tempPageTotal = Math.floor(total/pageSize)+1;
			}
			return tempPageTotal;
		},
		getPageCount : function(total,pageNo,pageSize){
			var tempPageCount = 1;
			if(total/pageNo < pageSize){
				tempPageCount = total%pageSize;
			}else{
				tempPageCount = pageSize;
			}
			return tempPageCount;
		},
		pointMove : function(keycode,topId,bottomId,leftId,rightId,contentCount,rowCount){//只支持矩形x行*y列移动
			var focusId = "", id = "", nowId = document.activeElement.id, index = 0, _index = 0, _indexOf = 0, subLength = 0;
			var tempStr = nowId.substring(nowId.length-2,nowId.length);
			if(isNaN(tempStr)){
				tempStr = nowId.substring(nowId.length-1,nowId.length);
				if(isNaN(tempStr)){
					return false;
				}else{
					subLength = 1;
					id = nowId.substring(0,nowId.length-1);
					if(!$(id+"0")){
						_indexOf = 1;
					}
				}
			}else{
				subLength = 2;
				id = nowId.substring(0,nowId.length-2);
				if(!$(id+"00")){
					_indexOf = 1;
				}
			}
			index = parseInt(tempStr,10);
			switch(keycode){
				case 37:
					if(leftId == true){
						return false;
					}
					_index = index-1;
					focusId = (index <= _indexOf || (index-_indexOf)%rowCount == 0) ? leftId : _index < 10 && subLength == 2 ? id+"0"+_index : id+_index;
					break;
				case 38:
					if(topId == true){
						return false;
					}
					_index = index - rowCount;
					focusId = $(_index < 10 && subLength == 2 ? id+"0"+_index : id+_index) ? _index < 10 && subLength == 2 ? id+"0"+_index : id+_index : topId;
					break;
				case 39:
					if(rightId == true){
						return false;
					}
					_index = (index-_indexOf)+1;
					index += 1;
					focusId = (_index%rowCount == 0 || index == (contentCount+_indexOf)) ? rightId : ((index < 10 && subLength == 2) ? id+"0"+index : id+index);
					break;
				case 40:
					if(bottomId == true){
						return false;
					}
					_index = index + rowCount;
					focusId = $(_index < 10 && subLength == 2 ? id+"0"+_index : id+_index) ? _index < 10 && subLength == 2 ? id+"0"+_index : id+_index : bottomId;
					break;
			}
			if(focusId.indexOf("keyCode_") != -1){
				return focusId;
			}else{
				if($(focusId)){
					$(focusId).focus();
				}
				return true;
			}
		}
	}

	var commonFocus = {
		allFocus : function(id, focusId, pic, scale, x_width, y_height){//焦点框改变样式,id当前焦点ID，focusId效果框ID，pic效果图片，scale放大倍数，x_width宽度增加，y_height高度增加
			$(id).style.zIndex="100";
			var newwidthpx = commonTools.delPX($(id).style.width);
			var newheightpx = commonTools.delPX($(id).style.height);
			$(focusId).childNodes[0].width = parseInt(newwidthpx,10)+parseInt(x_width,10);
			$(focusId).childNodes[0].height = parseInt(newheightpx,10)+parseInt(y_height,10);
			var nowTop = commonTools.delPX($(id).style.top)-parseInt(y_height/2,10);
			var nowLeft = commonTools.delPX($(id).style.left)-parseInt(x_width/2,10);
			$(focusId).childNodes[0].src=pic;
			$(focusId).style.top = nowTop+"px";
			$(focusId).style.left = nowLeft+"px";
			$(focusId).style.webkitTransitionDuration ="50ms";
			if($(id).childNodes[0].style){
				$(id).childNodes[0].style.webkitTransform='scale('+scale+')';
			}else{
				$(id).style.webkitTransform='scale('+scale+')';
			}
			$(focusId).childNodes[0].style.webkitTransform='scale('+scale+')';
		},
		allUnFocus : function(id,focusId){//失去焦点后还原，id焦点ID，focusId效果框ID
			if($(id).childNodes[0].style){
				$(id).childNodes[0].style.webkitTransform='scale(1.0)';
			}else{
				$(id).style.webkitTransform='scale(1.0)';
			}
			$(focusId).childNodes[0].style.webkitTransform='scale(1.0)';
		},
		restoreTextForPicUnFocus : function(id, numLeft, numTop){//失去焦点后还原文字
			var mov_text = $(id);
			var nowLeft = delete_px(mov_text.style.left);
		    var nowWidth = delete_px(mov_text.style.width);
		    var nowTop = delete_px(mov_text.style.top);
		    mov_text.style.left = (parseInt(nowLeft,10)+parseInt(numLeft,10))+"px";
		    mov_text.style.width = (parseInt(nowWidth,10)-(parseInt(numLeft,10)*2))+"px";
		    mov_text.style.top = (parseInt(nowTop,10)-parseInt(numTop,10))+"px";
		},
		updateTextForPicFocus : function(id, numLeft, numTop){//文字根据图片的放大调整
			var mov_text = $(id);
		    var nowLeft = delete_px(mov_text.style.left);
		    var nowWidth = delete_px(mov_text.style.width);
		    var nowTop = delete_px(mov_text.style.top);
		    mov_text.style.left = (parseInt(nowLeft,10)-parseInt(numLeft,10))+"px";
		    mov_text.style.width = (parseInt(nowWidth,10)+(parseInt(numLeft,10)*2))+"px";
		    mov_text.style.top = (parseInt(nowTop,10)+parseInt(numTop,10))+"px";
		}
	}

	var commonDate = {
		timeFormat : function(seconds,format){//时间格式化，seconds秒，format格式，返回转换后时间格式
			var hour = commonTools.zeroPad(Math.floor(seconds/3600),2);
			var minute = commonTools.zeroPad(Math.floor(seconds/60-hour*60),2);
			var ss = commonTools.zeroPad(Math.floor(seconds-hour*3600-minute*60),2);
			return ""+hour+format+minute+format+ss;
		},
		currentDate : function(len){//获取当前时间，len为时间长度
			var returnVal = "";
			var now = new Date();
		    var year = now.getFullYear();
		    var month = now.getMonth() + 1;
		    var day = now.getDate();
		    var hour = now.getHours();
		    var minute = now.getMinutes();
		    month = commonTools.zeroPad(month,2);
		    day = commonTools.zeroPad(day,2);
		    hour = commonTools.zeroPad(hour,2);
		    minute = commonTools.zeroPad(minute,2);
		    returnVal = ""+year+""+month+""+day+""+hour+""+minute;
		    returnVal = returnVal.substring(0,len);
		    return returnVal;
		}
	}
</script>

<script type="text/javascript">
	String.prototype.startWith=function(str){
		if( str==null || str=="" || this.length==0 || str.length>this.length){
			return false;
		}
		if(this.substring(0,str.length)==str){
			return true;
		}else{
			return false;
		}
		return true;
	}

	String.prototype.endWith=function(s){
		if(s==null ||s=="" || this.length==0 || s.length>this.length){
			return false;
		}
		if(this.substring(this.length - s.length)==s){
			return true;
		}else{
			return false;
		}
		return true;
	}
</script>
